export default {
    namespaced:true,
    state:{
        avatarUrl:uni.getStorageSync('avatarUrl') || '',
        nickName:uni.getStorageSync('nickName') || '',
        token:uni.getStorageSync('token') || ''
    },
    mutations:{
        updataAvatarUrl(state,payload){
            state.avatarUrl = payload
            uni.setStorageSync('avatarUrl', payload)
        },
        updataNickName(state,payload){
            state.nickname = payload
            uni.setStorageSync('nickName', payload)
        },
        updataToken(state,payload){
            state.token = payload
            uni.setStorageSync('token',payload)
        }
    },
    actions:{
      async getUserToken(context){
    const [ error , res ] = await uni.getUserInfo()
      // console.log(res);
    const { encryptedData,rawData,iv,signature } = res
    const [ error1 , { code } ] =await uni.login()
      // console.log(res1);
    const data = {
        encryptedData,
        rawData,
        iv,
        signature,
        code
      }
    const resLogin = await uni.$u.http.post('/users/wxlogin',data)
      console.log(resLogin);
      const token = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIxMywiaWF0IjoxNjcxOTM5MDE2LCJleHAiOjEwMDE2NzE5MzkwMTV9.08RrN6fmclZLJBVGmOwAulBQQ705x5_xrD_ZYyCjSQ4'
      context.commit('updataToken',token)
    }
    }
}